package com.hm.services;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.encoding.Md5PasswordEncoder;

import com.hm.DAO.ChmDAO;
import com.hm.model.DaysEntity;
import com.hm.model.EventsEntity;
import com.hm.model.MandatoryEntity;
import com.hm.model.UserEntity;

public class ChmServiceImpl implements ChmService{
	
	@Autowired
	private ChmDAO dataService;
	
	public ChmDAO getDataService() {
		return dataService;
	}

	public void setDataService(ChmDAO dataService) {
		this.dataService = dataService;
	}

	public void createUserRecord(String username, String password, String name){
		Md5PasswordEncoder ENC = new Md5PasswordEncoder();
		
		UserEntity user = new UserEntity();
		user.setUserName(username);
		user.setPassword(ENC.encodePassword(password, null));
		//user.setAccessLevel(1);
		//user.setEmailAddress("emailAddress@cvs.co.uk");
		//user.setFirstName(name);
		//user.setDate(new Date());
		this.dataService.createUserRecord(user);
	}
	
	public void storeUser(UserEntity user){
		this.dataService.storeUser(user);
	}

	@Override
	public void createHolidayRecord(DaysEntity day) {
		this.dataService.createHolidayRecord(day);
		
	}
	public void updateAccepted(Long id, String accepted){
		this.dataService.updateAccepted(id, accepted);
	}
	
	@Override
	public List<DaysEntity> getHols(){
		return this.dataService.getHols();
	}
	
	@Override
	public List<DaysEntity> getUnapprovedHols(){
		return this.dataService.getUnapprovedHols();
	}

	@Override
	public List<DaysEntity> getApprovedHols() {
		return this.dataService.getApprovedHols();
	}

	@Override
	public List<UserEntity> getUsers() {
		return this.dataService.getUsers();
	}

	@Override
	public void updateUserAllocation(String username, int allocation) {
		this.dataService.updateAllocation(username, allocation);
		
	}

	@Override
	public UserEntity searchDatabaseForUsername(String username) {
		return this.dataService.searchDatabaseForUsername(username);
	}

	@Override
	public void updateUserGroup(String username, String group) {
		this.dataService.updateGroup(username, group);
		
	}

	@Override
	public void createMandatoryRecord(MandatoryEntity mandatory) {
		this.dataService.createMandatoryRecord(mandatory);
		
	}

	@Override
	public List<MandatoryEntity> getMandatoryDays() {
		return this.dataService.getMandatoryDays();
	}

	@Override
	public void createEventRecord(EventsEntity event) {
		this.dataService.createEventRecord(event);
		
	}

	@Override
	public List<EventsEntity> getEvents() {
		// TODO Auto-generated method stub
		return this.dataService.getEvents();
	}
	
	
}
